package com.maidou.qiantai.service.impl;

import com.maidou.qiantai.domain.Attr;
import com.maidou.qiantai.domain.AttrAttrgroupRelation;
import com.maidou.qiantai.mapper.AttrAttrgroupRelationMapper;
import com.maidou.qiantai.service.IAttrAttrgroupRelationService;
import com.ruoyi.common.utils.DateUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品属性与分组关联Service业务层处理
 * 
 * @author maidou
 * @date 2024-03-13
 */
@Service
public class AttrAttrgroupRelationServiceImpl implements IAttrAttrgroupRelationService 
{
    @Resource
    private AttrAttrgroupRelationMapper attrAttrgroupRelationMapper;

    /**
     * 查询商品属性与分组关联
     * 
     * @param id 商品属性与分组关联主键
     * @return 商品属性与分组关联
     */
    @Override
    public AttrAttrgroupRelation selectAttrAttrgroupRelationById(Long id)
    {
        return attrAttrgroupRelationMapper.selectAttrAttrgroupRelationById(id);
    }

    /**
     * 查询商品属性与分组关联列表
     * 
     * @param attrAttrgroupRelation 商品属性与分组关联
     * @return 商品属性与分组关联
     */
    @Override
    public List<AttrAttrgroupRelation> selectAttrAttrgroupRelationList(AttrAttrgroupRelation attrAttrgroupRelation)
    {
        return attrAttrgroupRelationMapper.selectAttrAttrgroupRelationList(attrAttrgroupRelation);
    }

    /**
     * 新增商品属性与分组关联
     * 
     * @param attrAttrgroupRelation 商品属性与分组关联
     * @return 结果
     */
    @Override
    public int insertAttrAttrgroupRelation(AttrAttrgroupRelation attrAttrgroupRelation)
    {
        attrAttrgroupRelation.setCreateTime(DateUtils.getNowDate());
        return attrAttrgroupRelationMapper.insertAttrAttrgroupRelation(attrAttrgroupRelation);
    }

    /**
     * 修改商品属性与分组关联
     * 
     * @param attrAttrgroupRelation 商品属性与分组关联
     * @return 结果
     */
    @Override
    public int updateAttrAttrgroupRelation(AttrAttrgroupRelation attrAttrgroupRelation)
    {
        attrAttrgroupRelation.setUpdateTime(DateUtils.getNowDate());
        return attrAttrgroupRelationMapper.updateAttrAttrgroupRelation(attrAttrgroupRelation);
    }

    /**
     * 批量删除商品属性与分组关联
     * 
     * @param ids 需要删除的商品属性与分组关联主键
     * @return 结果
     */
    @Override
    public int deleteAttrAttrgroupRelationByIds(Long[] ids)
    {
        return attrAttrgroupRelationMapper.deleteAttrAttrgroupRelationByIds(ids);
    }

    /**
     * 删除商品属性与分组关联信息
     * 
     * @param id 商品属性与分组关联主键
     * @return 结果
     */
    @Override
    public int deleteAttrAttrgroupRelationById(Long id)
    {
        return attrAttrgroupRelationMapper.deleteAttrAttrgroupRelationById(id);
    }

    /**
     * 根据attr_id获取attrgroup分组id
     * @param attrIds
     * @return
     */
    @Override
    public List<Long> selectAttrGroupIdByAttrId(List<Long> attrIds) {
        List<Long>  ids= attrAttrgroupRelationMapper.selectAttrGroupIdByAttrId(attrIds);
        return ids;
    }

    /**
     * 根据分组id获取基本属性
     * @param id1
     * @return
     */
    @Override
    public List<Attr> selectToAttrByAttrGroupId(Long id1,List<Long> ids, Integer type) {
        if(id1==null||type==null||ids==null||ids.size()==0){
            return null;
        }
        return attrAttrgroupRelationMapper.selectToAttrByAttrGroupId(id1,ids,type);
    }

    @Override
    public void deleteAttrAttrgroupRelationByAttrIdAndAttrGroupIdBatch(List<Long> groupId, List<Long> collect) {
        attrAttrgroupRelationMapper.deleteAttrAttrgroupRelationByAttrIdAndAttrGroupIdBatch(groupId,collect);
    }
}
